// TestingThreading.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
//#include <thread>
//#include <iostream>
//#include "BackgroundThread.h"
//#include "Func.h"
//#include <exception>
//using namespace std;

//void SpeakHelloWorld()
//{
//	std::cout << "There lies the problem." << std::endl;
//}
//
//int _tmain(int argc, _TCHAR* argv[])
//{
//
//	int test;
//	
//	BackGroundWork work;
//	std::thread t(work);
//
//	
//
//	/*
//		we will be using this method to use a 
//		1) a local varibale which was given to the speciifc thread
//		2) to execute something both ways....i.e. both if the system fails at some point or not
//	*/
//
//	Func myFunc(10);
//
//	//we will do some coding in this thread thereofre 
//	std::cout << "please wait while we initialize the process" << std::endl;
//
//	try
//	{
//		//do some computation here 
//	}
//	catch (exception e)
//	{
//		//fire thread and handle error if an error happens
//		t.join();
//		throw;
//	}
//	//else just start the thread sinice nothing happened
//	t.join();
//
//	std::cin >> test;
//	return 0;
//}


#include <iostream>
#include <thread>
#include <chrono>

void foo(int mine)
{
	// simulate expensive operation
	std::this_thread::sleep_for(std::chrono::seconds(1));
	std::cout << "done from foo" << mine << std::endl;
}

void bar()
{
	// simulate expensive operation
	std::this_thread::sleep_for(std::chrono::seconds(3));
	std::cout << "done from bar" << std::endl;
}

int main()
{
	std::cout << "starting first helper...\n";
	std::thread helper1(foo, 5);

	std::cout << "starting second helper...\n";
	std::thread helper2(bar);

	std::cout << "waiting for helpers to finish..." << std::endl;
	helper1.join();
	//helper2.join();

	std::cout << "done!" <<helper1.joinable() <<"---"<< (bool)helper2.joinable() << "\n";
	//helper1.join();
	//helper2.join();
	try
	{

		helper1.join();
	}
	catch (std::exception e)
	{
		std::cout << e.what() << std::endl;
	}
	std::cin.ignore();
	
}
